package com.tjetc.dao.impl;

import com.tjetc.dao.CategoryDao;
import com.tjetc.domain.Category;
import com.tjetc.utils.Db;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import java.sql.SQLException;
import java.util.List;

public class CategoryDaoImpl implements CategoryDao {
    @Override
    public Category getById(int cid) throws SQLException {
        return Db.runner0().query("select *  from category where id=?",
                new BeanHandler<>(Category.class),
                cid);
    }

    @Override
    public List<Category> list() throws SQLException {
        return Db.runner0().query("select * from category",
                new BeanListHandler<>(Category.class));
    }
}
